﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;

namespace FeatureModelCore.FMShapes
{
    public class FMCircle
    {
        public readonly static string _XML_RADIUS = "Radius";

        public double Radius { get; internal set; }
        public FMPoint Center { get; internal set; }

        public FMCircle()
        {
            Radius = -1;
            Center = new FMPoint();
        }

        public FMCircle(double radius, FMPoint center)
        {
            Radius = radius;
            Center = center;
        }

        #region XML Parser
        /// <summary>
        /// To Xml Element
        /// </summary>
        /// <param name="xelem"></param>
        public void ToXElem(XElement xelem)
        {
            Center.ToXElem(xelem);
            xelem.Add(new XAttribute(_XML_RADIUS, Radius));
        }
        /// <summary>
        /// Parse Xelement to FMCircle
        /// </summary>
        /// <param name="xelem"></param>
        /// <returns></returns>
        public static FMCircle ParseXElem(XElement xelem)
        {
            FMPoint center = FMPoint.ParseXElem(xelem);
            double radius = -1;

            XAttribute xRadius = xelem.Attribute(_XML_RADIUS);
            if (xRadius != null)
            {
                radius = double.Parse(xRadius.Value);
            }
            return new FMCircle(radius, center);
        }
        #endregion
    }
}
